﻿using MediatR;
using U.B.DoMain;
using U.B.ErrorCode;
using U.B.ReadApi.Command;
using U.B.Repistory;

namespace U.B.ReadApi.CommandHander
{
    public class GetUsersCommandHander : IRequestHandler<GetUsersCommand, ApiResult<User>>
    {
        private readonly IRepistory<User> _usersRepository;
        public GetUsersCommandHander(IRepistory<User> usersRepository)
        {
            _usersRepository = usersRepository;
        }
        public Task<ApiResult<User>> Handle(GetUsersCommand request, CancellationToken cancellationToken)
        {
            ApiResult<User> result = new ApiResult<User>();
            var a = _usersRepository.GetAll().FirstOrDefault(x => x.UserId == request.UserId);
            result.code = Renum.显示成功;
            result.Message = Renum.显示成功.ToString();
            result.Data = a;
            return Task.FromResult(result);
        }
    }
}
